/**
 * Created by Administrator on 2018/10/28.
 */
$(function () {
    var $mobile = $('#findPassword-mobile');
    var $password = $('#findPassword-password');
    var $vCode = $('#findPassword-vCode');
    var $getCodeBtn = $('#findPassword-getCodeBtn');
    var $findPasswordSub = $('#findPassword-sub');

    $getCodeBtn.on('click', function () {
        var mobile = $mobile.val();
        if (!mobile) {
            _alert('请输入手机号');
            return;
        }
        ajax({
            url: 'sms/sendSmsCode',
            data: {
                phone:mobile,
                type:'find_pwd'
            },
            success: function (d) {
                _alert('发送成功');
            },
            fail: function () {
                _alert('发送验证码失败');
            }
        })
    });


    $findPasswordSub.on('click', function () {
        var mobile = $mobile.val();
        var vCode = $vCode.val();
        var password = $password.val();
        if (!mobile) {
            _alert('请输入手机号');
            return;
        }
        if (!vCode) {
            _alert('请输入验证码');
            return;
        }
        if (!password) {
            _alert('请输入新密码');
            return;
        }
        ajax({
            url: 'app/user/findAccount',
            data: {
                phone: mobile,
                smsCode: vCode,
                password: password
            },
            success: function (d) {
                _alert('找回密码成功');
                window.location.href = 'login.html';
            },
            fail: function () {
                _alert('找回密码失败');
            }
        })
    });
});